load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_license//rules:license.bzl", "license")

package(
    default_applicable_licenses = [
        ":license.APACHE",
        ":license.BSD",
        ":license.MINPACK",  # Only used by unsupported/** not by Eigen/**.
        ":license.MPL2",
    ],
)

exports_files(glob(["COPYING.*"]))

# Note: Eigen is primarily an MPL2 library with small bits of code under other
# licenses. Previous versions of Eigen contained LGPL code which needed to be
# carefully excluded, but as of approximately 2023-02-07 all LGPL code has been
# removed upstream so does not need any special handling here.

license(
    name = "license.APACHE",
    license_kinds = ["@rules_license//licenses/spdx:Apache-2.0"],
    license_text = "COPYING.APACHE",
)

license(
    name = "license.BSD",
    license_kinds = ["@rules_license//licenses/spdx:BSD-3-Clause"],
    license_text = "COPYING.BSD",
)

license(
    name = "license.MINPACK",
    license_kinds = ["@rules_license//licenses/spdx:BSD-3-Clause-Attribution"],
    license_text = "COPYING.MINPACK",
)

license(
    name = "license.MPL2",
    license_kinds = ["@rules_license//licenses/spdx:MPL-2.0"],
    license_text = "COPYING.MPL2",
)

HDRS = glob(
    [
        "Eigen/**",
        "unsupported/Eigen/**",
    ],
    exclude = [
        # We don't want any documentation files.
        "**/*.md",
        "**/*.txt",
        "unsupported/Eigen/NonLinearOptimization",
        "unsupported/Eigen/MatrixFunctions",
        "unsupported/Eigen/Polynomials",
    ],
)

cc_library(
    name = "eigen",
    hdrs = HDRS,
    includes = ["."],
    visibility = ["//visibility:public"],
)
